<template>
  <view class="container" @touchmove.stop="handleTouchMove">
    <u-navbar :is-back="false" title="福利待遇" title-size="36" :border-bottom="false">
      <view class="slot-wrap dis-flex flex-y-center" @click="cancelEidt()">
        <u-icon name="arrow-left" size="42" style="margin-left: 20rpx; font-weight: 100"></u-icon>
      </view>
    </u-navbar>
    <scroll-view class="scroll-Y" scroll-y="true">
      <view class="wrapper">
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
        <view class="card">
          <view class="tl">福利标签</view>
          <view class="des">福利标签，字数限制6字以内</view>
          <u-line></u-line>
          <view class="fuli-list dis-flex flex-y-center">
            <view class="fuli-item" v-for="(fuli, i) in form.fulis" :key="i">
              <text>{{ fuli.name }}</text>
              <view class="closeBtn" @click="closeFuli(i)">-</view>
            </view>
            <view class="dis-flex flex-y-center">
              <input
                v-model="fulibox"
                class="fuli-item"
                style="width: 180rpx; margin-right: 20rpx"
                placeholder="请输入标签"
              />
              <view class="add" @click="addFuli">＋</view>
            </view>
          </view>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
        <view class="card">
          <view class="tl">员工福利说明</view>
          <view class="des">员工福利说明，字数限制100字以内</view>
          <u-line></u-line>
          <view class="des-list">
            <view class="des-item" v-for="(fuli, i) in form.fulis" :key="i">
              <view class="des-tl">{{ fuli.name }}</view>
              <u-input
                class="textarea"
                v-model="fuli.des"
                type="textarea"
                height="160"
                :border="true"
                :clearable="true"
                style="padding: 20rpx; font-size: 26rpx"
              />
            </view>
          </view>
        </view>
        <u-gap height="40" bg-color="#F0F1F2"></u-gap>
      </view>
    </scroll-view>
    <view class="fixed-wapper">
      <view class="submit-btn" @click="onsubmit">确认</view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'welfare',
  props: {
    content: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      readOnly: false,
      formats: {},
      fulibox: '',
      form: {
        fulis: [
          {
            name: '五险一金'
          },
          {
            name: '周末双休'
          },
          {
            name: '周末双休'
          },
          {
            name: '周末双休'
          },
          {
            name: '年终奖励'
          },
          {
            name: '哇哇'
          }
        ]
      }
    }
  },
  onLoad(options) {},
  methods: {
    handleTouchMove(event) {
      console.log('handleTouchMove')
      // 使用 event.stopPropagation() 阻止事件冒泡
      event.stopPropagation()
    },
    onsubmit() {
      this.$emit('submit')
    },
    cancelEidt() {
      const app = this
      uni.showModal({
        title: '友情提示',
        content: '确认要放弃编辑吗？放弃后系统不会自动保存以下内容。',
        success(o) {
          if (o.confirm) {
            app.$emit('closeEditor')
          }
        }
      })
    },
    addFuli() {
      this.form.fulis.push({
        name: this.fulibox
      })
      this.fulibox = ''
    },
    closeFuli(index) {
      this.form.fulis.splice(index, 1)
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/style/btn.css';

.container {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  height: 100%;
  background: #f0f1f2;
}

.scroll-Y {
  height: 90%;
}

.wrapper {
  background-color: #f0f1f2;
  padding: 0 20rpx;
}

.card {
  padding: 30rpx 20rpx;
  background-color: #fff;
  border-radius: 10rpx;
  .tl {
    font-size: 30rpx;
    color: #333333;
    margin-bottom: 20rpx;
  }
  .des {
    font-size: 26rpx;
    color: #999999;
    margin-bottom: 20rpx;
  }
}

.add {
  color: #fff;
  width: 36rpx;
  height: 36rpx;
  background-color: #10a28f;
  border-radius: 50%;
  line-height: 30rpx;
  text-align: center;
  margin-top: 30rpx;
}

.fuli-list {
  flex-wrap: wrap;
  width: 100%;

  .fuli-item {
    height: 70rpx;
    background: #f5f5f5;
    border-radius: 10rpx;
    border: 1px solid #e6e6e6;
    font-size: 30rpx;
    color: #666666;
    margin-right: 50rpx;
    line-height: 70rpx;
    padding: 0 24rpx;
    width: auto;
    margin-top: 30rpx;
    position: relative;

    .closeBtn {
      position: absolute;
      width: 32rpx;
      height: 32rpx;
      line-height: 30rpx;
      background-color: #fa453c;
      color: #fff;
      border-radius: 50%;
      text-align: center;
      top: -15rpx;
      right: -15rpx;
    }
  }
}
.des-list {
  margin-top: 10rpx;
  .des-item {
    margin-top: 30rpx;
    .des-tl {
      font-size: 26rpx;
      color: #333333;
      margin-bottom: 20rpx;
    }
  }
}

.textarea {
  background-color: #f5f5f5;
  border-radius: 10rpx;
}
.fixed-wapper {
  background-color: #fff;
  width: 100%;
  left: 0;
  padding-left: 2%;
  height: 96rpx;
  justify-content: flex-end;
  padding-right: 20rpx;

  .submit-btn {
    width: 100%;
    margin-top: 14rpx;
    height: 70rpx;
    line-height: 70rpx;
  }
}
</style>
